{include file="public/layout" /}
<link href="__SKIN__/css/template.css" rel="stylesheet" type="text/css">
<body class="bodystyle" style="overflow-x: hidden; padding: 0; min-width: 674px; background: #fff;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="height: 100%;">
    <div class="maincon maintab wintit" onselectstart="return false;">
        <div class="districts">
            {volist name="$provinceList" id="vo"}
            <div class="province">
                <input type="hidden" class="page_province_name" id="page_province_name_{$vo.id}">
                <label class="checkbox-inline" style="margin-left: 20px;">
                    <input type="checkbox" class="cityall" value="{$vo.id}" id="province_id_{$vo.id}" province="{$vo.name}">{$vo.name}
                    <span class="citycount" style="color: #ff6600;"></span>
                </label>

                <ul style="display: none;">
					<i class="jt"><i></i></i>
                    {volist name="$vo.cityList" id="ci"}
                    <li>
                        <label class="checkbox-inline">
                            <input type="checkbox" class="city province_id_{$vo.id}" cityid="{$ci.id}" city="{$ci.name}" provinceid="{$vo.id}" province="{$vo.name}">{$ci.name}
                        </label>
                    </li>
                    {/volist}
                </ul>
            </div>
            {/volist}
        </div>
    </div>

    <input type="hidden" id="page_city_ids">
    <input type="hidden" id="special_id" value="{$special_id}">
</div>
<script type="text/javascript">
    $(function() {
        $('.province').mouseover(function() {
            $(this).find('ul').show();
        }).mouseleave(function() {
            $(this).find('ul').hide();
        });

        // 设置已选区域
        var special_id = $('#special_id').val();
        var special_ids = parent.$('#special_ids_'+special_id).val();
        if (special_ids != undefined && special_ids.length > 0) {
            var ids = special_ids.split(",");
            $.each(ids, function(k, v) {
                $(".city[cityid='"+v+"']").attr("checked", "checked").parents(".province").find(".cityall").attr("checked", "checked");
            });
            $(".city:checked").parents(".province").each(function() {
                var count = $(this).find('.city:checked').length;
                if (count > 0) {
                    $(this).find(".citycount").html("(" + count + ")");
                    // 赋值处理
                    var provinceID = $(this).find('.city:checked').attr('provinceid');
                    var provinceName = $(this).find('.city:checked').attr('province');
                    var cityTotal = $(this).find('.city').length;
                    if (parseInt(cityTotal) === parseInt(count)) {
                        $('#page_province_name_' + provinceID).val(provinceName);
                    } else {
                        var cityName = [];
                        $(this).find('.city').each(function() {
                            if (true === $(this).get(0).checked) cityName.push($(this).attr('city'));
                        });
                        if (parseInt(cityName.length) > 0) provinceName += '(' + cityName.join(',') + ')';
                        $('#page_province_name_' + provinceID).val(provinceName);
                    }
                } else {
                    $(this).find(".citycount").html("");
                }
            });
        }

        // 选择一级区域
        $('.cityall').click(function() {
            var checked = $(this).get(0).checked;
            var citys = $(this).parent().parent().find('.city');
            citys.each(function() {
                $(this).get(0).checked = checked;
            });

            var count = 0;
            if (checked) count = $(this).parent().parent().find('.city:checked').length;
            if (count > 0) {
                $(this).next().html("(" + count + ")");
            } else {
                $(this).next().html("");
            }
            var provinceID = $(this).val();
            if (true === checked) {
                var provinceName = $(this).attr('province');
                $('#page_province_name_' + provinceID).val(provinceName);
            } else {
                $('#page_province_name_' + provinceID).val('');
            }

            var page_city_ids = '';
            $('.city:checked').each(function() {
                page_city_ids += $(this).attr('cityid') + ",";
            });
            $('#page_city_ids').val(page_city_ids);
        });

        // 选择二级区域
        $('.city').click(function() {
            var checked = $(this).get(0).checked;
            var cityall = $(this).parents(".province").find('.cityall');
            if (checked) cityall.get(0).checked = true;

            // 选中数
            var count = cityall.parent().parent().find('.city:checked').length;
            // 下级总数
            var provinceID = $(this).attr('provinceid');
            var provinceName = $(this).attr('province');
            var cityTotal = cityall.parent().parent().find('.city').length;
            if (parseInt(cityTotal) === parseInt(count)) {
                $('#page_province_name_' + provinceID).val(provinceName);
            } else {
                var cityName = [];
                cityall.parent().parent().find('.city').each(function() {
                    if (true === $(this).get(0).checked) cityName.push($(this).attr('city'));
                });
                if (parseInt(cityName.length) > 0) provinceName += '(' + cityName.join(',') + ')';
                $('#page_province_name_' + provinceID).val(provinceName);
            }

            if (count > 0) {
                cityall.next().html("(" + count + ")");
            } else {
                cityall.next().html("");
                cityall.attr('checked', false);
                $('#page_province_name_' + provinceID).val('');
            }

            var page_city_ids = '';
            $('.city:checked').each(function() {
                page_city_ids += $(this).attr('cityid') + ",";
            });
            $('#page_city_ids').val(page_city_ids);
        });
    });
</script>
{include file="public/footer" /}